package com.example.demo.model.DTO;

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKBReader;

public class Location {
    private double x; // 经度
    private double y; // 纬度

    // 构造函数，接受 WKB 数据
    public Location(String wkbString) {
        try {
            WKBReader reader = new WKBReader();
            byte[] wkb = WKBReader.hexToBytes(wkbString);
            Geometry geometry = reader.read(wkb);
            if (geometry instanceof Point) {
                Point point = (Point) geometry;
                this.x = point.getX();
                this.y = point.getY();
            }
        } catch (ParseException e) {
            e.printStackTrace();
            // 处理解析异常，可能需要进一步处理或记录错误
        }
    }
    public Location(double x,double y){
        this.x=x;
        this.y=y;

    }
    // Getters 和 Setters
    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}
